#!/bin/bash
#
# Customized for TVB.COM
# description: Image Infrastructure Export Image Consumer
# chkconfig: 2345 99 00

# Source function library.
. /etc/rc.d/init.d/functions
. /opt/message/etc/conslib

# Consumer Parameters.
PROGDIR=/opt/image_infrastructure/libexec
LOGDIR=/data/image_infrastructure/logs
CONSUMER=export_image_consumer

PHP=/opt/php/bin/php
cons=${PROGDIR}/${CONSUMER}.php
prog=${CONSUMER}
pidfile=/var/run/${CONSUMER}.pid
lockfile=/var/lock/subsys/${CONSUMER}
logfilePrefix=${LOGDIR}/${CONSUMER}
RETVAL=0

start() {
	echo -n $"Starting $prog: "
	startCons $cons $logfilePrefix $pidfile $lockfile
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && touch ${lockfile}
	return $RETVAL
}

# When stopping consumer a delay of >10 second is required before SIGKILLing the
# consumer parent; this gives enough time for the consumer parent to SIGKILL any
# errant children.
stop() {
	echo -n $"Stopping $prog: "
	killproc -d 10 $cons
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  *)
	echo $"Usage: $prog {start|stop|restart|help}"
	exit 1
esac

exit $RETVAL
